<template>
  <div style="height: 100%">
    <g-dynamic-table
      type="dataautolog"
      ref="table"
      :fetch="fetchDataList"
      @action-click="handleActionClick"
    >
    </g-dynamic-table>
  </div>
</template>

<script lang="ts">
  import { AppComponentBase } from '/@/shared/component-base';
  import { EntityChangeHistoryServiceProxy, EntityChangeListDto } from '/@/shared/service-proxies';
  import dayjs from 'dayjs';
  import 'dayjs/locale/zh-cn';
  import { defineComponent } from 'vue';
  import dataauditlogsdetail from './data-audit-logs-detail/data-audit-logs-detail.vue';
  import GDynamicTable from '/@/shared/components/g-dynamic-table/index.vue';
  dayjs.locale('zh-cn');

  export default defineComponent({
    name: 'data-audit-logs-news',
    components: { dataauditlogsdetail, EntityChangeListDto, GDynamicTable },
    mixins: [AppComponentBase],
    data() {
      return {
        // 是否显示高级过滤
        advancedFiltersVisible: false,
        selectedRows: [],
        entityChangeHistory: new EntityChangeHistoryServiceProxy(this.$apiUrl, this.$api),
        /** 选中 */
        Items: [] as any,
      };
    },
    methods: {
      /**查询数据 */
      fetchDataList() {
        const { maxResultCount, skipCount, sorting, DateRange, UserName, Object } = (
          this.$refs.table as any
        ).getSearchProps();
        return new Promise((resolve, reject) => {
          this.entityChangeHistory
            .getPagedEntityChanges(
              !DateRange ? undefined : DateRange[0],
              !DateRange ? undefined : DateRange[1],
              UserName,
              Object,
              sorting,
              maxResultCount,
              skipCount,
            )
            .finally(() => {
              // finishedCallback!();
            })
            .then((res) => {
              resolve(res);
              // this.showPaging(res);
            })
            .catch((error) => {
              reject(error);
            });
        });
      },
      /**
       * 查看详情
       */
      getDetails(item?: EntityChangeListDto) {
        this.modalHelper.create(dataauditlogsdetail, { pageDataList: item }).subscribe((res) => {
          if (res) {
            this.refresh();
          }
        });
      },

      /**
       * 按钮回调事件
       */
      handleActionClick(event: string, item?: any) {
        console.log(event);
        switch (event) {
          case 'ViewDetails':
            this.getDetails(item);
            break;
          default:
            break;
        }
      },
    },
  });
</script>

<style scoped lang="less">
  .subscriptionEndUtc {
    text-align: center;
  }
  .list-table {
    width: 100%;
    white-space: nowrap;
  }
  // table
  .modal-body {
    padding: 0;
    min-width: 100%;
  }

  :deep(.ant-table-tbody > tr > td) {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    &:last-child {
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: inherit;
    }
  }

  .table-edit {
    .anticon {
      margin-right: 10px;
    }
  }
  .detail {
    white-space: nowrap;
  }

  .table-delete,
  .ant-dropdown-link {
    margin-left: 20px;
  }

  .table--container {
    margin-top: 20px;
  }
</style>
